<template>
  <div>
    <Row>
      <Col span="24">
        <Span style="font-size: 18px">模拟工具</Span>
      </Col>
    </Row>
    <Card>
      <Form ref="formValidate" label-position="right" :label-width="200">
      <Row>
        <Col span="3">
          <input  @change= "fileChange" type="file" id="fileInput" class="file-input" accept=".tsv,.txt" v-show="false">
          <Button @click="selectFile">读取文件</Button>
        </Col>
        <Col>
          <Button @click="showKline">K线图</Button>
        </Col>
        <Col span="6">
          <FormItem label="日期选择">
            <Date2Picker ref="date2Picker" v-model="dateRange" :placeholder="日期"></Date2Picker>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="总行数">
            <span>{{rowCount}}</span>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="总列数">
            <span>{{colCount}}</span>
          </FormItem>
        </Col>
        <Col>
          <FormItem label="错误信息">
            <span v-show="error">{{errorMessage}}</span>
          </FormItem>
        </Col>
      </Row>
      </Form>
      <Table border :columns="columns" :data="tableData" height="600" >
      </Table>
      <GbPage v-model="page" @changePage="changePage"></GbPage>
    </Card>
    <Modal draggable v-model="kline.show"  :title="kline.title"  :mask-closable="false" :footer-hide=true width="1440px" >
      <KLine ref="kline"></KLine>
    </Modal>
  </div>
</template>
<script>
import Date2Picker from './Date2Picker.vue'
import KLine from './KLine.vue'
import GbPage from './GbPage.vue'
import moment from 'moment'
export  default {
  components: {GbPage,Date2Picker,KLine},
  data(){
    return{
      fileInput: null,
      errorMessage: null,
      error: false,
      rowCount: 0,
      colCount: 0,
      kline:{
        show: false,
        title: 'K线图'
      },
      page: {
        pages: 1,
        size: 50,
        total: 0,
        current: 1
      },
      tableData:[],
      dateRange: [],
      columns:[
        { title: '日期', key: 'date', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
/*        { title: '开盘', key: 'open', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '最高', key: 'high', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '最低', key: 'low', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '收盘', key: 'close', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '成交量', key: 'volume', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '换手率', key: 'turnover_rate', resizable: true, sortable: true, width: 190, ellipsis: true, tooltip: true, tooltipTheme: 'light' }, */
        {title: '均线',align: 'center',children:
          [
            { title: '5日均', key: 'avg5', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            { title: '20日均', key: 'avg20', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            { title: '40日均', key: 'avg40', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
          ]
        },
        { title: '当前价', key: 'HqCurrPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '基准价', key: 'basePrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        {
          title: '卖出条件', align: 'center', children:
            [
              { title: '卖出价', key: 'maxPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '最高价', key: 'hqMaxPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            ]
        },
        {
          title: '买入条件', align: 'center', children:
            [ { title: '买入价', key: 'minPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '最低价', key: 'hqMinPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            ]
        },
        {
          title: '买入', align: 'center', children:
          [
            { title: '买数量', key: 'buyQty', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            { title: '买入价', key: 'buyPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            { title: '买金额', key: 'buyAmount', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
          ]
        },
        {
          title: '卖出', align: 'center', children:
            [
              { title: '卖数量', key: 'sellQty', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '卖出价', key: 'sellPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '卖金额', key: 'sellAmount', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            ]
        },
        {
          title: '持仓量', align: 'center', children:
            [
              { title: '持仓量', key: 'costQty', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '持仓价', key: 'costPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '持仓金额', key: 'costAmount', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            ]
        },
        {
          title: '盈亏', align: 'center', children:
            [
              { title: '盈利', key: 'profitAmount', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '盈利率', key: 'profitRate', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
              { title: '实盈亏', key: 'realProfit', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
            ]
        },
        { title: '当前价', key: 'currPrice', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '当前金额', key: 'currAmount', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
        { title: '斜率', key: 'slope', resizable: true, sortable: true, width: 120, ellipsis: true, tooltip: true, tooltipTheme: 'light' },
      ],
      fullData:[],
      myList:[], // 经过买卖操作，盈利计算后的列表
      // 统计数据
      total:{
        maxCost: 0.0, // 最大投资
        maxProfit: 0.0, // 最多盈利
        maxLoss: 0.0, // 最大浮亏
        floatProfit: 0.0 // 浮盈浮亏
      },
      avg: {
        d5: [],  // 5日平均
        d20: [], // 20日平均
        d40: [],  // 40日平均
        listAvg5: [], // 5日均值

        lineAvg5: 0.0, // 5日线
        lineAvg20: 0.0, // 20日线
        lineAvg40: 0.0  //  40日线
      },
      lineSlope: 0.0, // 斜率
      lookbackPeriod : 1, // 几日前的斜率
      limitMoney: 30000, //资金额限制
      coopRate: 0.05, // 网格比率
      baseQty: 0, // 每次购买数量
    }
  },
  methods:{
    /**
     * 字符转日期
     * @param str
     * @returns {null|Date}
     */
    toDate(str) {
      // console.log("toDate_str: ",str)
      //let cleaned = str.trim();
      let date = new Date(str);
      return isNaN(date.getTime()) ? null : date;
    },
    /**
     * 文件选择
     */
    selectFile(){
      this.fileInput.click();
    },
    /**
     * 文件选择后
     */
    fileChange(){
      if (this.fileInput.files.length) {
        this.handleFile(this.fileInput.files[0]);
      }
    },
    /**
     * 读取处理
     * @param file
     */
    handleFile(file){
      // 隐藏错误信息
      this.error =false;

      // 验证文件类型
      if (!file.name.match(/\.(tsv|txt)$/i)) {
        this.$Message.error('请选择TSV或TXT文件');
        return;
      }

      // 显示文件信息
      //fileSize.textContent = formatFileSize(file.size);

      // 读取文件
      const reader = new FileReader();
      const _this = this;
      reader.onload = function(e) {
        try {
          const content = e.target.result;
          _this.parseTSV(content);
        } catch (error) {
          console.log(error)
          _this.$Message.error({content: '解析文件时出错: ' + error.message, duration: 10});

        }
      };

      reader.onerror = function() {
        _this.$Message.error('读取文件时出错');
      };

      reader.readAsText(file, 'GB2312');
    },
    /**
     * 翻页
     */
    changePage(){
      this.tableData = []
      if (this.myList.length ===0){
        return;
      }
      // 取商数
      let quotient = Math.floor(this.myList.length / this.page.size);
      // 取余数
      let remainder = this.myList.length % this.page.size;
      this.page.pages = remainder > 0 ? quotient+1 : quotient;
      this.page.total = this.myList.length;
      this.page.current =  this.page.current > this.page.pages ? this.page.pages : this.page.current
      for(let i=(this.page.current-1)*this.page.size; i<this.page.current * this.page.size; i++){
        const rowData = {...this.myList[i]}
        rowData.date = moment(rowData.date).format("YYYY-MM-DD");
        this.tableData.push(rowData)
      }
    },
    /**
     * 文件内容解析
     * @param content
     */
    parseTSV(content){
      // 按行分割
      const lines = content.split('\n');

      if (lines.length === 0) {
        this.$Message.error('文件为空');
        return;
      }
      // init
      this.fullData=[]
      this.tableData=[]
      this.myList=[]
      this.avg.d5=[]
      this.avg.d20=[]
      this.avg.listAvg5=[]
      this.avg.lineAvg5=0.0
      this.avg.lineAvg20=0.0
      this.avg.lineAvg40=0.0
      this.lineSlope=0.0


      // 解析表头
      const headers = lines[0].split('\t');
      console.log("headers1: ",lines[0].split('\t'))
      //console.log("headers2: ",lines[1].split('\t'))
      console.log("headers3: ",lines[2].split('\t'))
      //console.log("headers4: ",lines[3].split('\t'))
      // 解析数据行
      this.fullData = [];
      for (let i = 2; i < lines.length; i++) {
        if (lines[i].trim() === '') continue; // 跳过空行

        const values = lines[i].split('\t');
        const row = {};

        row['date']=this.toDate(values[0])
        row['open']=this.toNumber(values[1])
        row['high']=this.toNumber(values[2])
        row['low']=this.toNumber(values[3])
        row['close']=this.toNumber(values[4])
        row['volume']=this.toNumber(values[5])
        row['turnover_rate']=this.toNumber(values[6])
        // 将每列的值与表头对应
        headers.forEach((header, index) => {
          row[header.trim()] = values[index] ? values[index].trim() : '';
        });

        this.fullData.push(row);
      }
      console.log("data: ",this.fullData)
      // 更新统计信息
      this.rowCount = this.fullData.length;
      this.colCount = headers.length;

      this.playByCoop()

      // 显示统计卡片
      //statsCard.style.display = 'block';

      // 显示预览
      //displayPreview(headers, data);
    },
    /**
     * 安全的转换方式字符转数字
     * @param str
     * @returns {null|number}
     */
    toNumber(str) {
      // console.log("str: ",str)
      //let cleaned = str.trim();
      let num = Number(str);
      return isNaN(num) ? 0 : num;
    },

    /**
     * 网格交易
     */
    playByCoop(){
      const startDate = new Date("2024-01-09");
      const endDate = new Date("2024-12-31");
      let count =0;
      let firstRow = true;

      let tempData ={
        qty: 0.0, //数量
        basePrice: 0.0, //基准价
        maxPrice: 0.0, //卖出价
        minPrice: 0.0, //买入价
        amount: 0.0, //金额
        maxCost: 0.0, // 最大投入
        currCost: 0.0, // 当前投入
        maxProfit: 0.0, // 盈利清算
        maxLoss: 0.0, // 最大浮亏
        floatProfit: 0.0 // 浮盈
      }

      let preData={}
      this.myList = []
      for(let i in  this.fullData) {
         console.log("preData: %o",preData.costAmount)
        count++;
        const row = this.fullData[i]
        // 指定日期之内
        if (startDate){
          if (row.date < startDate || row.date>endDate){
            continue;
          }
        }

        let myData = this.createMyData();
        myData.date =row.date
        myData.hqMaxPrice =row.high
        myData.hqMinPrice =row.low
        myData.hqCurrPrice =row.close
        myData.currPrice =row.close //当前单价
        myData.volume =row.volume //成交量
        myData.turnover_rate =row.turnover_rate //换手率

        myData.basePrice =tempData.basePrice //基准价
        myData.minPrice =tempData.minPrice //买入价
        myData.maxPrice =tempData.maxPrice //卖出价

        myData.costQty =this.toNumber(preData.costQty) //数量
        myData.costPrice =this.toNumber(preData.costPrice) //单价
        myData.costAmount =this.toNumber(preData.costAmount) //金额

        // 计算 5日 20日平均
        this.averageCalculation(row.close);
        myData.avg5 =this.avg.lineAvg5  // 5日均线
        myData.avg20 =this.avg.lineAvg20  // 20日均线
        myData.avg40 =this.avg.lineAvg40  // 40日均线
        myData.slope = this.lineSlope.toFixed(2) // 斜率

        // 判断是否买卖
        let flag = 0
        //if (count >= 40){ // 40日以后才能卖
          // 多头排列
          if (this.avg.lineAvg5 > this.avg.lineAvg20 && this.avg.lineAvg20 > this.avg.lineAvg40){
            if (firstRow) {
              // 第一次买，底仓
              firstRow = false;
              this.baseQty = Math.round(this.limitMoney / row.open / 100) * 100;
              tempData.currCost = (this.baseQty * row.open).toFixed(2); // 当前成本
              this.buy(myData, preData, tempData, this.baseQty, row.open, this.coopRate);
            }
            else
            {
              // 阳线当日是先买后卖
              if (row.close >= row.open) {
                if (row.low < myData.minPrice) {
                  // 最低价小于买入基准价 ，按买入基准价买
                  flag = 1;
                  this.baseQty = Math.round(this.limitMoney / row.open / 100) * 100;
                  this.buy(myData, preData, tempData, this.baseQty, myData.minPrice, this.coopRate);
                }
                if (row.high > myData.maxPrice) {
                  // 最高价大于卖出基准价，按卖出基准价卖
                  if (flag === 1) {
                    myData = this.genNewMyData(myData, row, tempData, preData);
                    preData = {...myData}
                  }
                  this.sell(myData, preData, tempData, this.baseQty, myData.maxPrice, this.coopRate);
                }
              }else { // 阴线当日先卖后买
                if (row.high > myData.maxPrice) {
                  // 最高价大于卖出基准价，按卖出基准价卖
                  flag = 1;
                  this.sell(myData, preData, tempData, this.baseQty, myData.maxPrice, this.coopRate);
                }
                if (row.low < myData.minPrice) {
                  // 买
                  if (flag === 1) {
                    myData = this.genNewMyData(myData, row, tempData, preData);
                    preData = {...myData}
                  }
                  this.baseQty = Math.round(this.limitMoney / row.open / 100) * 100;
                  this.buy(myData, preData, tempData, this.baseQty, myData.minPrice, this.coopRate);
                }
              }
            }
          }
          else
          {
            // 20日线以下清空
            if (myData.costQty > 0){
              this.sell(myData, preData, tempData, myData.costQty, row.open, this.coopRate);
            }
            firstRow = true;
          }
        //}

        this.calculateTotal(tempData, myData,preData);

        this.myList.push(myData);

        preData = {...myData}
      } // end of for(let i in  this.fullData)

      // 统讲数据
      this.total.maxCost = tempData.maxCost
      this.total.maxProfit = tempData.maxProfit
      this.total.maxLoss = tempData.maxLoss
      this.total.floatProfit = tempData.floatProfit

      this.page.current = 1;
      this.changePage();
    },

    /**
     * 平均价计算
     * @param price
     */
    averageCalculation(price){
      let total = 0.0;

      // console.log("this.avg: %o", this.avg)

      if (this.avg.d5.length >= 5){
        this.avg.d5.splice(0,1);
      }
      this.avg.d5.push(price);
      for(let i in this.avg.d5){
        total = total + this.avg.d5[i];
      }
      this.avg.lineAvg5 = (total/this.avg.d5.length).toFixed(2)

      if (this.avg.listAvg5.length >= 5){
        this.avg.listAvg5.splice(0,1);
      }
      this.avg.listAvg5.push(this.avg.lineAvg5);

      total = 0.0;
      if (this.avg.d20.length >= 20){
        this.avg.d20.splice(0,1);
      }
      this.avg.d20.push(price);
      for(let i in this.avg.d20){
        total = total + this.avg.d20[i];
      }
      this.avg.lineAvg20 = (total/this.avg.d20.length).toFixed(2)

      total = 0.0;
      if (this.avg.d40.length >= 40){
        this.avg.d40.splice(0,1)
      }
      this.avg.d40.push(price);
      for(let i in this.avg.d40){
        total = total + this.avg.d40[i];
      }
      this.avg.lineAvg40 = (total/this.avg.d40.length).toFixed(2)

      if (this.avg.listAvg5.length >= 4){
        const currentMA5 = this.avg.listAvg5[this.avg.listAvg5.length - 1];    // 最新的5日线值
        const pastMA5 = this.avg.listAvg5[this.avg.listAvg5.length - 1 - this.lookbackPeriod];   // n天前的5日线值

        // 计算斜率： (现在 - 过去) / 周期
        // lineSlope =  (currentMA5 - pastMA5) / 3;
        this.lineSlope = this.calculateMangle(currentMA5, pastMA5, this.lookbackPeriod);
      }
    },
    /**
     * 计算均线的倾斜角度（标准化，不受价格绝对值影响）
     * @param currentValue 当前均线值 (e.g., 当前5日均价)
     * @param pastValue    N周期前的均线值 (e.g., 5天前的5日均价)
     * @param period       时间周期 (N) - 横坐标的长度
     * @return {number|*} 倾斜角度（度数）。正数表示向上倾斜，负数表示向下倾斜。
     */
    calculateMangle(currentValue, pastValue, period) {
      // 1. 防止除以0的错误
      if (pastValue === 0.0) {
        return 0.0;
      }

      // 2. 计算价格的百分比变化率
      const priceChangeRatio = (currentValue - pastValue) / pastValue;

      // 3. 计算斜率：价格变化率 / 时间周期
      // 这相当于 tan(θ)
      const slopeRatio = priceChangeRatio / period;

      // 4. 使用反正切函数计算弧度制的角度，然后转换为度数
      const angleInDegrees = Math.atan(slopeRatio) * (180 / Math.PI)

      return angleInDegrees;
    },

    /**
     * 买入
     * @param myData
     * @param preData
     * @param tempData
     * @param bsQty
     * @param buyPrice
     * @param rate
     */
    buy(myData, preData, tempData, bsQty, buyPrice, rate){
      console.log("buy: costAmount: %o; bsQty: %o", myData.costAmount, bsQty)
      myData.buyQty = bsQty
      myData.buyPrice = buyPrice
      myData.buyAmount = (bsQty * buyPrice).toFixed(2)

      // 持仓数量，单价，金额
      const amount = bsQty*buyPrice
      myData.costQty = myData.costQty>0 ? myData.costQty + bsQty : bsQty; // 持仓数量
      myData.costAmount = myData.costAmount>0 ? (myData.costAmount + amount).toFixed(2) : (amount).toFixed(2); // 持仓金额
      myData.costPrice = myData.costQty>0 ? (myData.costAmount/myData.costQty).toFixed(2) : 0 //成本价

      // 下一轮的卖出价，买入价
      tempData.basePrice = buyPrice // 新基准价
      tempData.maxPrice = (buyPrice * (1+rate)).toFixed(2)  // 新卖出价
      tempData.minPrice = (buyPrice * (1-rate)).toFixed(2)  // 新买入价

      //console.log("buy: costQty: %o; bsQty: %o", myData.costQty, bsQty)
    },

    /**
     * 卖出
     * @param myData
     * @param preData
     * @param tempData
     * @param bsQty
     * @param sellPrice
     * @param rate
     */
    sell(myData,preData,tempData,bsQty, sellPrice, rate){
      //console.log("sell: costAmount: %o; bsQty: %o", myData.costAmount, bsQty)

      if (myData.costQty >= bsQty){
        const cost = myData.costAmount;

        myData.sellQty = bsQty
        myData.sellPrice = sellPrice
        myData.sellAmount = (bsQty * sellPrice).toFixed(2)

        const amount = bsQty*sellPrice
        myData.costQty  = myData.costQty - bsQty
        myData.costAmount = (myData.costAmount - amount).toFixed(2)
        myData.costPrice = myData.costQty ? (myData.costAmount/myData.costQty).toFixed(2) : 0 //成本价

        // 清空了
        if (myData.costQty === 0.0){
          myData.realProfit  = (bsQty*sellPrice-cost).toFixed(2); //真实盈亏
          myData.costAmount  = 0.0;
          myData.costPrice  = 0.0
        }
      }
      // 下一轮的卖出价，买入价
      tempData.basePrice = sellPrice // 新基准价
      tempData.maxPrice = (sellPrice * (1+rate)).toFixed(2)  // 新卖出价
      tempData.minPrice = (sellPrice * (1-rate)).toFixed(2)  // 新买入价
    },

    /**
     * 生成新的 MyData
     * @param myData
     * @param row
     * @param tempData
     * @param preData
     * @returns {*}
     */
    genNewMyData(myData,row, tempData, preData){
      this.calculateTotal(tempData, myData,preData);

      this.myList.push(myData);

      // 复制 myData 到 preData
      preData = { ...myData };

      const newData = this.createMyData()
      newData.date = row.date
      newData.hqMaxPrice = row.high
      newData.currPrice = row.close
      newData.hqMinPrice = row.low
      newData.hqCurrPrice = row.close
      newData.basePrice = tempData.basePrice
      newData.minPrice = tempData.minPrice
      newData.maxPrice = tempData.maxPrice

      newData.costQty = this.toNumber(preData.costQty)
      newData.costPrice = this.toNumber(preData.costPrice)
      newData.costAmount = this.toNumber(preData.costAmount)
      return newData;
    },

    /**
     * 计算合计数
     * @param tempData
     * @param myData
     * @param preData
     */
    calculateTotal(tempData, myData, preData){

      tempData.maxCost = tempData.maxCost < myData.costAmount ? myData.costAmount:tempData.maxCost;
      tempData.currCost = myData.costQty === 0 ? 0 : tempData.currCost;

      // maxCost < myData
      myData.currAmount = (myData.currPrice * myData.costQty).toFixed(2);
      myData.profitAmount = myData.currAmount - myData.costAmount;
      myData.profitRate = tempData.currCost=== 0 ? 0 : (myData.profitAmount / tempData.currCost * 100).toFixed(2);

      if (myData.profitAmount < 0){
        if (tempData.maxLoss > myData.profitAmount){
          tempData.maxLoss = myData.profitAmount
        }
      }

      // 真实盈利
      if (myData.realProfit > 0){
        tempData.maxProfit = tempData.maxProfit + myData.realProfit;
      }
      // 当天盈利
      if (myData.buyAmount > 0){
        myData.todayProfitAmount = myData.currAmount - myData.costAmount
      } else if (myData.sellAmount > 0)
      {
        myData.todayProfitAmount = myData.sellAmount - this.toNumber(preData.currAmount);
      }else if (preData != null && this.toNumber(preData.currAmount) > 0)
      {
        myData.todayProfitAmount = myData.currAmount - this.toNumber(preData.currAmount)
      }

      tempData.floatProfit = myData.profitAmount;
    },

    /**
     * 创建并初始化一个 MyData对象
     */
    createMyData(){
      return {
        buyQty: 0.0,
        buyPrice: 0.0,
        buyAmount: 0.0,
        sellQty: 0.0,
        sellPrice: 0.0,
        sellAmount: 0.0,

        date: null,
        hqMaxPrice: 0.0,
        hqMinPrice: 0.0,
        hqCurrPrice: 0.0,
        currPrice: 0.0,
        volume: 0.0,
        turnover_rate: 0.0,

        // 下一轮的卖出价，买入价
        basePrice: 0.0, // 基准价
        minPrice: 0.0,  //买入价
        maxPrice: 0.0,  //卖出价

        // 持仓数量，单价，金额
        costQty: 0.0, // 持仓数量
        costPrice: 0.0, //成本价
        costAmount: 0.0, // 持仓金额

        todayProfitAmount: 0.0,
        floatProfit: 0.0,
        realProfit: 0.0,

        // 计算 5日 20日平均
        avg5: 0.0,
        avg20: 0.0,
        avg40: 0.0,
        slope: 0.0 // 斜率
      }
    },

    /**
     * K线图
     */
    showKline(){
      this.kline.show = true
      this.$refs.kline.openDialog();
    }
  },
  mounted() {
    this.fileInput = document.getElementById('fileInput');
  }
}
</script>
<style>

</style>
